#pragma once

#include "corebase_global.h"
#include <osg/Referenced>
#include <osg/Vec3>
#include <ode/common.h>

namespace CoreBase
{
	class Transformable;

	class COREBASE_EXPORT ODEWorldWrap : public osg::Referenced
	{
	public:
		ODEWorldWrap();
		///get the ODE world ID
		dWorldID getWorldID() const;
		/**
		* Perform one step of the physics system of the supplied time.
		* @param stepSize : the number of seconds to iterate the world.
		*/
		void step(const double &stepSize);
		///set the gravity vector
		void setGravity(const osg::Vec3& gravity);
		///set the gravity vector
		void setGravity(float x, float y, float z);
		///get the gravity vector
		void getGravity(osg::Vec3& vec) const;
		///get the gravity vector
		osg::Vec3 getGravity() const;
		///get the gravity vector
		void getGravity(float &x, float &y, float &z) const;
		/** Register a collidable/physical object with the World.
		* @param collidable A valid object to insert into the physics world.
		*/
		void registerCollidable(Transformable* collidable);
		/** Remove the supplied collidable/physical object from the world.
		* @param collidable A valid object to remove from the physics world.
		*/
		void unRegisterCollidable(Transformable* collidable);
		/** set the world's default damping parameters.  Bodies will use the world's
		* parameters by default.  Default scale is zero, meaning no
		* damping will take place.
		* @param linearScale the damping scale factor to apply to linear velocities
		* @param angularScale The angular scale factor to apply to angular velocities
		*/
		void setDamping(float linearScale, float angularScale);
		/** get the world's linear damping scale value.
		* @return The linear velocity damping scale value
		*/
		float getLinearDamping() const;
		/** get the world's angular damping scale value.
		* @return The angular velocity damping scale value
		*/
		float getAngularDamping() const;
		/** set the world's linear velocity damping threshold.  If an object's
		* linear velocity is above this value, the linear damping scale
		* will be applied.  Default is 0.01
		* @param linearThreshold The linear velocity threshold above which, the
		*        body will be dampened.  Use zero to disable damping.
		* @see setDamping()
		*/
		void setLinearDampingThreshold(float linearThreshold);
		/** get the world's linear velocity damping threshold.
		* @return The linear velocity damping threshold.
		*/
		float getLinearDampingThreshold() const;
		/** set the world's angular velocity damping threshold.  If an object's
		* angular velocity is above this value, the angular damping scale
		* will be applied.  Default is 0.01
		* @param angularThreshold The angular velocity threshold above which, the
		*        body will be dampened.  Use zero to disable damping.
		* @see setDamping()
		*/
		void setAngularDampingThreshold(float angularThreshold);
		/** get the world's angular velocity damping threshold.
		* @return The angular velocity damping threshold.
		*/
		float getAngularDampingThreshold() const;
	protected:
		virtual ~ODEWorldWrap();
	private:
		dWorldID _worldID;  ///<The generated world ID
		osg::Vec3 _gravity; ///<The current gravity vector
	};
}